//package com.ganhuoshitang.multipledatasources.config;
//
//import org.apache.ibatis.session.SqlSessionFactory;
//import org.mybatis.spring.SqlSessionFactoryBean;
//import org.mybatis.spring.SqlSessionTemplate;
//import org.mybatis.spring.annotation.MapperScan;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.boot.context.properties.ConfigurationProperties;
//import org.springframework.boot.jdbc.DataSourceBuilder;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Primary;
//import org.springframework.jdbc.datasource.DataSourceTransactionManager;
//import org.springframework.transaction.PlatformTransactionManager;
//
//import javax.sql.DataSource;
//import java.util.HashMap;
//import java.util.Map;
//
///**
// * 数据源切换工具
// * @author 公众号：干货食堂
// */
//@Configuration
////@MapperScan(basePackages = {"com.ganhuoshitang.multipledatasources.mapper.db2"}, sqlSessionFactoryRef = "sqlSessionFactory2")
//public class DataSourceConfig2 {
//
//    /**
//     * 数据源2
//     * spring.datasource.db2：application.properteis中对应属性的前缀
//     * @return
//     */
//    @Bean(name = "db2")
//    @ConfigurationProperties(prefix = "spring.datasource.db2")
//    public DataSource dataSourceTwo() {
//        return DataSourceBuilder.create().build();
//    }
//
//    @Bean("sqlSessionFactory2")
//    public SqlSessionFactory sqlSessionFactory2(@Qualifier("db2") DataSource dataSource) throws Exception {
//        SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
//        sqlSessionFactoryBean.setDataSource(dataSource);
//
//        return sqlSessionFactoryBean.getObject();
//    }
//
//    @Bean("sqlSessionTemplate2")
//    public SqlSessionTemplate sqlSessionTemplate2(@Qualifier("sqlSessionFactory2") SqlSessionFactory sqlSessionFactory) {
//        return new SqlSessionTemplate(sqlSessionFactory);
//    }
//
//
//}
